function __args() {
	var setting = {};
	if (arguments.length === 1 && typeof arguments[0] !== 'string') {
		setting = arguments[0];
	} else {
		setting.url = arguments[0];
		if (typeof arguments[1] === 'object') {
			setting.data = arguments[1];
			setting.success = arguments[2];
		} else {
			setting.success = arguments[1];
		}
	}
	if (setting.url.indexOf('http://') !== 0) {
		//http://120.27.18.4/index.php/
		//http://shops.wudhl.com/index.php/WXAPIhttps://www.505coder.com
    // setting.url = 'https://505coder.com/index.php/WXAPI' + setting.url;
    setting.url = 'https://app.yiguangjie.com' + setting.url +'?web_key=RKp9ufgcGshw48qiZHmMYx6dUSQP2Ca0';
	}
	return setting;
}
function __json(method, setting) {
	setting.method = method;
	setting.header = {
    'Content-type': 'text/html; charset=UTF-8'
	};

  // wx.request(setting);
  wx.request({
    url: setting.url, //仅为示例，并非真实的接口地址
    data: setting.data,
    method: setting.method,
    header: {
      'content-type': 'application/x-www-form-urlencoded' // 默认值
        // 'content-type': 'application:json;charset=utf8'
    },
    success: setting.success
  })

}

module.exports = {
	getJSON: function () {
		__json('GET', __args.apply(this, arguments));
	},
	postJSON: function () {
    __json('POST', __args.apply(this, arguments));
	},
	sendTemplate: function (formId, templateData, success, fail) {
		var app = getApp();
		this.getJSON({
			url: '/WxAppApi/sendTemplate',
			data: {
				rd_session: app.rd_session,
				form_id: formId,
				data: templateData,
			},
			success: success,   // errorcode==0时发送成功
			fail: fail
		});
	},
    send:function(url,methods,data){
        return new Promise((rev,rej)=>{
            wx.request({
                url: 'https://app.yiguangjie.com' + url + '?web_key=RKp9ufgcGshw48qiZHmMYx6dUSQP2Ca0',
                method:methods,
                data:data,
                success:res=>{
                    if(res.data.status=='201'){
                        getApp().globalData.username="";
                        getApp().globalData.token = "";
                        wx.showToast({
                            title: '请登录',
                            icon:'none'
                        })
                        return 
                    }
                    rev(res.data)
                },
                fail:(error)=>{
                    console.log(error);
                }
            })
        })
    }
}

